package njClass.UI
{
	import mx.core.UIComponent;
	
	import spark.components.RichEditableText;
	import spark.components.Scroller;
	import spark.utils.TextFlowUtil;
	
	public class RichTextBar extends UIComponent
	{
		private var _scroller:Scroller=new Scroller();
		private var _richTextField:RichEditableText=new RichEditableText();
		
		public function RichTextBar(_width:Number,_height:Number,_horizontalScrollPolicy:Boolean=false,_verticalScrollPolicy:Boolean=true)
		{
			//TODO: implement function
			super();
			
			_richTextField.width=_width;
			_richTextField.height=_height;
			
			_richTextField.setStyle("editable","false");
			_richTextField.setStyle("selectable","false");
			
			_scroller.width=_width;
			_scroller.height=_height;
			
			_scroller.setStyle("horizontalScrollPolicy",_horizontalScrollPolicy?"auto":"off");
			_scroller.setStyle("verticalScrollPolicy",_verticalScrollPolicy?"auto":"off");
			
			_scroller.viewport=_richTextField;
			
			this.addChild(_scroller);
		}
		
		/**
		 * 
		 * @param _data
		 * 数据源 允许XML、String、Number对象
		 * 
		 */		
		public function set text(_data:Object):void{
			switch(typeof(_data)){
				case "xml":
					_richTextField.content=TextFlowUtil.importFromXML(_data as XML);
					break;
				case "string":
					_richTextField.content=_data;
					break;
				case "number":
					_richTextField.content=_data.toString();
					break;
			}
		}
		
		public function get text():Object{
			
			return null;
		}
	}
}